package com.esfak47.mediafetcher.app.event;

import com.esfak47.mediafetcher.core.event.Event;
import com.esfak47.mediafetcher.core.event.EventGroupEnum;
import com.esfak47.mediafetcher.core.event.EventHandler;

import java.util.Set;

/**
 * @author tony
 * @date 2018/5/21
 */
public class EventHandlerDelegate implements EventHandler {
    private final EventHandler eventHandler;

    public EventHandlerDelegate(EventHandler eventHandler) {
        this.eventHandler = eventHandler;
    }

    @Override
    public Set<EventGroupEnum> getSupportGroup() {
        return eventHandler.getSupportGroup();
    }

    @Override
    public Set<String> supportSubject() {
        return eventHandler.supportSubject();
    }

    @Override
    public void onEvent(Event event) {
        if ((this.supportSubject() != null && supportSubject().contains(event.getSubject()))) {
            eventHandler.onEvent(event);
        } else if (this.eventHandler.supportAllSubject()) {
            eventHandler.onEvent(event);
        }
    }
}
